export class LoginPage {
    constructor(onLogin) {
        this.onLogin = onLogin;
        this.container = null;
    }

    render() {
        if (!this.container) {
            this.container = document.createElement('div');
            this.container.className = 'login-container';
            this.container.innerHTML = `
                <div class="login-box">
                    <h2>登录</h2>
                    <form id="login-form">
                        <div class="form-group">
                            <input type="text" class="username" placeholder="用户名" required>
                        </div>
                        <div class="form-group">
                            <input type="password" class="password" placeholder="密码" required>
                        </div>
                        <button type="submit">登录</button>
                    </form>
                    <div class="register-link">
                        <a href="#/register">没有账号？立即注册</a>
                    </div>
                </div>
            `;

            const form = this.container.querySelector('#login-form');
            form.addEventListener('submit', (e) => {
                e.preventDefault();
                const username = this.container.querySelector('.username').value;
                const password = this.container.querySelector('.password').value;
                this.onLogin(username, password);
            });
        }
        return this.container;
    }
} 